home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlibs.zip / STRNMOV.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  2KB  |  72 lines

  1. ;       Static Name Aliases
  2. ;
  3.         TITLE   strnmov
  4. ;       NAME    strnmov.C
  5.  
  6. ;   strnmov(dst, src, n) moves up to n characters of  src  to  dst.   It
  7. ;   always  moves  exactly n characters to dst; if src is shorter than n
  8. ;   characters dst will be extended on the right with NULs, while if src
  9. ;   is longer than n characters dst will be a truncated version of src.
  10. ;   Unlink the UNIX version, dst will have a NUL appended.
  11. ;
  12. ;   The result is a pointer to the first NUL in dst.
  13.  
  14.         .287
  15. _TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  16. _TEXT   ENDS
  17. _DATA   SEGMENT  WORD PUBLIC 'DATA'
  18. _DATA   ENDS
  19. CONST   SEGMENT  WORD PUBLIC 'CONST'
  20. CONST   ENDS
  21. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  22. _BSS    ENDS
  23. DGROUP  GROUP   CONST,  _BSS,   _DATA
  24.         ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  25. EXTRN   __chkstk:NEAR
  26. _TEXT      SEGMENT
  27.         PUBLIC  _strnmov
  28. _strnmov        PROC NEAR
  29.         push    bp
  30.         mov     bp,sp
  31.         push    di
  32.         push    si
  33.         mov     di,[bp+4]       ;dst
  34.         mov     si,[bp+6]       ;src
  35.  
  36. ;       dst = 4
  37. ;       register di = dst
  38. ;       src = 6
  39. ;       register si = src
  40. ;       n = 8
  41.  
  42.         mov     cx,[bp+8]
  43.         jcxz    cleanup
  44. $loop:
  45.         movsb
  46.         cmp     byte ptr [si - 1],0
  47.         je      pad
  48.         loop    $loop
  49.         jmp     short cleanup
  50. pad:
  51.         xor     al,al
  52.         mov     si,di
  53.         repnz   stosb
  54.         mov     di,si
  55.         dec     di
  56. cleanup:
  57.         cmp     byte ptr [di],0
  58.         je      $out
  59.         xor     al,al
  60.         mov     [di],al
  61. $out:
  62.         xchg    ax,di
  63.         pop     si
  64.         pop     di
  65.         mov     sp,bp
  66.         pop     bp
  67.         ret
  68.  
  69. _strnmov        ENDP
  70. _TEXT   ENDS
  71. END
  72.